package com.wrial.mall.search.config;
/*
 * @Author  Wrial
 * @Date Created in 19:18 2020/5/18
 * @Description 配置ES的一些信息
 */

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 整合ES
 * 1.导入依赖
 * 2.配置RestHighLevelClient Bean
 * 3.根据官方文档进行API操作
 */
@Configuration
public class MallElasticSearchConfig {

    public static final RequestOptions COMMON_OPTIONS;

    static {
        // 基于默认规则加一些通用设置项，可以后期根据需求添加options
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bearer " + TOKEN);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory
//                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024))
        COMMON_OPTIONS = builder.build();
    }


    @Bean
    public RestHighLevelClient esRestClinet() {
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("120.27.240.223", 9200, "http")));
        return client;
    }
}
